package com.controller;

import com.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/my")
public class MyController {

    @RequestMapping("/hello")
    public String hello(){
        return "hello11133333344444555";
    }

    // 请求方式默认是没有作限制的，写了RequestMethod才作限制
    @RequestMapping(value = "/path/{a}/{b}", method = RequestMethod.POST)
    public String pathVariable(@PathVariable int a, @PathVariable int b) {
        return Integer.toString(a + b);
    }

    // 等价于上面
    @PostMapping("/path2/{a}/{b}")
    public String pathVariable2(@PathVariable int a, @PathVariable int b) {
        return Integer.toString(a + b);
    }

    /*http://localhost:8080/my/rep?firstname=slow&secondname=goat*/
    @GetMapping("/rep")
    public String requestParams(@RequestParam("firstname") String a, @RequestParam("secondname") String b) {
        return a + b;
    }

    /*http://localhost:8080/my/user?id=1&name=小明&age=19*/
    @GetMapping("/user")
    public void UserTest(User user) {
        System.out.println(user);
    }

    @PostMapping("/chinese")
    public void chineseTest(String name) {
        System.out.println(name);
    }
}
